package com.yx.yinshanjinniu.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.yx.yinshanjinniu.R;
import com.yx.yinshanjinniu.base.BaseActivity;
import com.yx.yinshanjinniu.bean.CreateOrderResultBean;
import com.yx.yinshanjinniu.utils.RouteUtil;
import com.zc.mychart.utils.FormatUtil;


/**
 * Created by Mr on 2018/6/24.
 */

public class UserLevelUpDialog extends Dialog implements View.OnClickListener {
    private Context mContext;
    private ImageView iv_close;
    private ImageView iv_level;
    private ImageView iv_level_name;
    private TextView tv_go_check_rights;
    private TextView tv_discount_remark;
    private TextView tv_discount_value;
    private Button bt_dialog_confirm;
    private int[] levels;
    private int[] levelTitles;

    public UserLevelUpDialog(@NonNull Context context) {
        super(context, R.style.dialog);
        mContext = context;
        levels = new int[]{R.drawable.img_level_up_2, R.drawable.img_level_up_3, R.drawable.img_level_up_4,
                R.drawable.img_level_up_5, R.drawable.img_level_up_6,R.drawable.img_level_up_7};
        levelTitles = new int[]{R.drawable.img_level_title_2, R.drawable.img_level_title_3,
                R.drawable.img_level_title_4, R.drawable.img_level_title_5, R.drawable.img_level_title_6,R.drawable.img_level_title_7};
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_level_up, null);
        findViews(view);
        setContentView(view);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    private void findViews(View view) {
        iv_close = (ImageView) view.findViewById(R.id.iv_close);
        iv_level = view.findViewById(R.id.iv_level);
        iv_level_name = view.findViewById(R.id.tv_level_name);
        tv_go_check_rights = view.findViewById(R.id.tv_go_check_rights);
        tv_discount_remark = (TextView) view.findViewById(R.id.tv_discount_remark);
        tv_discount_value = (TextView) view.findViewById(R.id.tv_discount_value);
        bt_dialog_confirm = (Button) view.findViewById(R.id.bt_dialog_confirm);
        bt_dialog_confirm.setOnClickListener(this);
        iv_close.setOnClickListener(this);
        tv_go_check_rights.setOnClickListener(this);
    }

    public void init(CreateOrderResultBean result) {
        int level = result.getLevel();
        double discount = result.getLevel_discount();
        tv_discount_remark.setText("你可以享受兑换商品");
        tv_discount_value.setText(FormatUtil.formatDouble2(discount));
        iv_level_name.setImageResource(levelTitles[level - 2]);
//        RequestOptions requestOptions = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL);
//        Glide.with(mContext).load(levels[level - 2]).apply(requestOptions).into(iv_level);
        iv_level.setImageResource(levels[level - 2]);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.tv_go_check_rights:
                //去用户中心
                RouteUtil.toUserCenterActivity((BaseActivity) mContext);
                dismiss();
                break;
            case R.id.bt_dialog_confirm:
                //去福利中心
                RouteUtil.toWelfareActivity((BaseActivity) mContext);
                dismiss();
                break;
        }
    }
}
